package com.webserver.core;

import com.webserver.http.HttpServletRequest;
import com.webserver.http.HttpServletResponse;

import java.io.File;

public class DispatcherServlet {
    public void service(HttpServletRequest request, HttpServletResponse response){
        //2.处理请求
        String path=request.getUri();
        System.out.println("请求抽象路径:"+path);
        File file=new File("./webapps"+path);
        //状态相关信息

        if (file.isFile()){
            response.setContentFile(file);
            response.addHeader("Content-Type","text/html");
            response.addHeader("Content-Length",file.length()+"");
        }else {
            response.setStausCode(404);
            response.setStausReason("Not Found");

            file=new File("./webapps/root/404.html");
            response.setContentFile(file);
            response.addHeader("Content-Type","text/html");
            response.addHeader("Content-Length",file.length()+"");

        }
        response.addHeader("Server","WebServer");
    }
}
